package com.wenx.concurrent.thread;

/**
 * 10个线程按照顺序执行
 */
public class UseJoin implements Runnable{


    private Thread thread;

    private Integer num;

    public UseJoin(Thread thread, Integer num) {
        this.thread = thread;
        this.num = num;
    }

    @Override
    public void run() {
        //执行此run方法前等待thread方法执行完成
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("run执行"+ num);
    }

    public static void main(String[] args) {
        Thread thread = Thread.currentThread();

        for (int i = 0; i < 10; i++) {
            Thread thread1 = new Thread(new UseJoin(thread,i));
            thread1.start();
            thread = thread1;
        }

        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("aa");

    }
}
